{include file="common/head"}
<style>
    a {
        text-decoration: none;
    }

    input {
        display: initial !important;
    }
</style>
<link rel="stylesheet" href="/static/flatpickr/flatpickr.min.css">
<script src="/static/flatpickr/flatpickr.min.js"></script>
</head>

<body>
    <!--startprint-->
    <div class="container-fluid" style="">

        <div class="row">
            <div class="col-4 fs-2">
                客户订单明细总表
            </div>

            <div class="col-8">
                <form id='form' action="/index.php/order/customer_order_list" method="post">
                    <div  id="query_bar" style="height: 50px;line-height: 50px;">

                        <label for="customer">客户：</label>
                        <select name="customer_id" class="form-control" style="width:140px;display:initial;">
                            <option value="">所有</option>
                            {foreach $customer_list as $k=>$v}
                                <option value="{$v['id']}" {if $v['id']==$customer} selected{/if}>{$v['name']} </option> 
                            {/foreach} 
                        </select> 

                        <label for="sdate">日期：</label>
                        <input class="form-control" type="text" value="{$sdate}" id="sdate" name="sdate" placeholder="开始日期" />

                        <label for="sdate"></label>
                        <input class="form-control" type="text" value="{$edate}" id="edate" name="edate" placeholder="结束日期" />

                        <label for="po">客户PO#</label>
                            <input class="form-control" type="text" value="{$po}" id="po" name="po" placeholder="客户订单号" />
 
                        <button type="button" class="btn btn-warning query">
                            <span class="bi-search"></span>
                        </button>


                    </div>
                </form>
            </div>
        </div>

        <table class="table  table-hover table-bordered table-striped">
            <thead class="table-info">
                <th>序号</th>
                <th>订单 PO#</th>
                <th>下单日期</th>
                <th>客户名称</th>
                <th>订单总数</th>
                <th>产品</th>
                <th>规格说明</th>
                <th>单位</th>
                <th>订购数量</th>
                <th>已发货</th>
                <th>待发货</th>
                <th>单价</th>
                <th>采购金额</th>
                <th>备注</th>
            </thead>
            <tbody>
                {foreach $list['data'] as $order}
                {foreach($order['goods_list'] as $kv)}
                <tr>
                    <td>{$kv['sn']}</td>
                    <td>
                        <c class='od' id="{$order['id']}" style="color:blue;cursor: pointer;"
                    >{$order['order_no']}</c>
                    </td>
                    <td>{$order['create_time']}</td>
                    <td>{$order['customer_name']}</td>
                    <td>{$order['qty']}</td>
                    <td>{$kv['name']}</td>
                    <td>{$kv['desc']}</td>
                    <td>{$kv['unit']}</td>
                    <td>{$kv['qty']}</td>
                    <td>{$kv['delivery_qty']}</td>
                    <td>{$kv['undelivery_qty']}</td>
                    <td>{$sys.currency_symbol}{$kv['price']}</td>
                    <td>{$sys.currency_symbol}{$kv['total']}</td>
                    <td>{$kv['memo']}</td>
                </tr>
                {/foreach}
                {/foreach}
            </tbody>
        </table>
        {include file="common/pagination"}
        <div class="row ">
            <div class="col">日期：{$date}</div>
            <div class="col">打印：{$uname}  
  
        </div>
    </div>
    <!--endprint-->
    <div class="text-center">
        <button class="btn btn-sm btn-primary" type="button" onclick="printpage();">
            <span class="bi-printer"></span> Print
        </button>
        <button type='button' class='btn btn-sm btn-info' id="excel">
            <span class="bi-file-x"></span>Export excel
        </button></div>
    </div>
    <div style="height:50px;text-align: center;color:#999"></div>
</body>
<script type="text/javascript">
    flatpickr("#sdate,#edate", {});

$(document).ready(function() {
    $(".query").on('click', function () {
        // var cid = $("#customer_id").val();
        // var order_no = $("#order_no").val();
        // var sdate = $("#sdate").val();
        // var edate = $("#edate").val();
        $("form").submit();
    })

    $("#excel").on('click',function(){
        $("#po").after("<input type='text' name='excel' value=1 />");
        $("form").submit();
        // $.ajax({
        // //几个参数需要注意一下
        //     type: "POST",//方法类型
        //     dataType: "json",//预期服务器返回的数据类型
        //     url: "/order/customer_order_list" ,
        //     data: $('form').serialize(),
        //     success: function (result) {
        //         console.log(result);//打印服务端返回的数据(调试用)
        //         if (result.resultCode == 200) {
        //             alert("SUCCESS");
        //         }
        //         ;
        //     },
        //     error : function() {
        //         alert("异常！");
        //     }
        // });

        $("input[name='excel']").remove();
    })
    // $("#excel").on('click',function(){
    //     //

    // })

    $(".od").on('click', function () {
        var oid = $(this).attr('id');
        layer.open({
            type: 2,
            title: '订单明细',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['900px', '600px'],
            content: '/index.php/order/order_list/id/' + oid
        });
    })



})

function printpage() {
    let oldStr = window.document.body.innerHTML; // 获取body的内容
    var el = document.getElementById('form');
    let start = "<!--startprint-->"; // 开始打印标识, 17个字符
    let end = "<!--endprint-->"; // 结束打印标识
    let newStr = oldStr.substr(oldStr.indexOf(start) + 17); // 截取开始打印标识之后的内容
    newStr = newStr.substring(0, newStr.indexOf(end)); // 截取开始打印标识和结束打印标识之间的内容
    newStr = newStr.replace(''+el.innerHTML+'','');
    window.document.body.innerHTML = newStr; // 把需要打印的指定内容赋给body
    window.print(); // 调用浏览器的打印功能打印指定区域
    window.document.body.innerHTML = oldStr; // body替换为原来的内容
}



</script>
</body>

</html>